package com.benio.ycfdisplayer.fresco;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import com.facebook.common.internal.Preconditions;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.interfaces.DraweeHierarchy;

/**
 * 该Target传入的View必须实现FrescoView
 * 用于Fresco自定义View
 * Created by zhangzhibin on 2016/9/1.
 */
public class FrescoTarget<V extends View & FrescoView> extends FrescoViewTarget<V> {

    public FrescoTarget(@NonNull V view) {
        super(view);
        Preconditions.checkArgument(view instanceof FrescoView, "Your view must implements FrescoView.");
    }

    @Override
    public final DraweeController getController() {
        FrescoView view = mView.get();
        return view != null ? view.getController() : null;
    }

    @Override
    public final void setController(@Nullable DraweeController draweeController) {
        FrescoView view = mView.get();
        if (view != null) {
            view.setController(draweeController);
        }
    }

    @Override
    public final DraweeHierarchy getHierarchy() {
        FrescoView view = mView.get();
        return view != null ? view.getHierarchy() : null;
    }

    @Override
    public final void setHierarchy(DraweeHierarchy hierarchy) {
        FrescoView view = mView.get();
        if (view != null) {
            view.setHierarchy(hierarchy);
        }
    }
}
